CREATE TABLE [dbo].[Hobbies](
	[CodeHobby] varchar(8) NOT NULL,
	[LblHobby] [varchar](250) NOT NULL,
	[OrderHobby] [int] NOT NULL,
	[CodeHobbyParent] varchar(8) NULL,

CONSTRAINT [PK_Hobbies] PRIMARY KEY CLUSTERED 
(
	[CodeHobby] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

CREATE TABLE [dbo].[UsersHobbies](
	[IdUserHobby] [bigint] IDENTITY(1,1) NOT NULL,
	[CodeHobby] varchar(8) NOT NULL,
	[IdUser] [bigint] NOT NULL,
	[Description] [varchar](max) NULL,
 CONSTRAINT [PK_UsersHobbies] PRIMARY KEY CLUSTERED 
(
	[IdUserHobby] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]


ALTER TABLE [dbo].[UsersHobbies]  WITH CHECK ADD  CONSTRAINT [FK_UsersHobbies_Hobbies] FOREIGN KEY([CodeHobby])
REFERENCES [dbo].[Hobbies] ([CodeHobby])

ALTER TABLE [dbo].[UsersHobbies] CHECK CONSTRAINT [FK_UsersHobbies_Hobbies]

ALTER TABLE [dbo].[UsersHobbies]  WITH CHECK ADD  CONSTRAINT [FK_UsersHobbies_Users] FOREIGN KEY([IdUser])
REFERENCES [dbo].[Users] ([IdUser])

ALTER TABLE [dbo].[UsersHobbies] CHECK CONSTRAINT [FK_UsersHobbies_Users]

GO

